using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Xeneize.SolaraBL.CRM;
using Xeneize.Utilities;

namespace WIntegrator.Pages.CRM
{
    public partial class CRMUploadDocument : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillFolderCombo();
            }
        }

        private void FillFolderCombo()
        {
            this.cmbFolder.DataSource = CCRMFolders.GetList(Convert.ToInt32(Request.QueryString["cc"]));
            this.cmbFolder.DataTextField = "Description";
            this.cmbFolder.DataValueField = "ID";
            this.cmbFolder.DataBind();
        }
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile)
            {
                CRMDocument doc = new CRMDocument();
                doc.Location = @"C:\Solara\Documents\";
                doc.Name = this.FileUpload1.FileName;
                doc.Folder =  new CRMFolder(Convert.ToInt32(this.cmbFolder.SelectedValue));
                doc.Description = this.txtDocDescription.Text;
                doc.Category = this.cmbCategory.SelectedItem.Text;
                try
                {
                    this.FileUpload1.SaveAs(doc.Location + doc.Name);
                    doc.Save();
                }
                catch (System.Exception ex)
                {
                    SolaraExceptions.Save(ex);
                }
                
            }
        }
    }
}
